package com.ossjk.qlh.tgb.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.system.annotation.LogModule;
import com.ossjk.core.system.annotation.LogOperation;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.tgb.entity.RetailUser;
import com.ossjk.qlh.tgb.service.IRetailUserService;
import com.ossjk.qlh.tgb.vo.RetailUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName RetailUserController
 * @Description 用户商户管理接口
 * @Author Jasper
 * @Date 2022/1/21 9:42
 */



@RestController
@RequestMapping("/tgb/RetailUser")
@Api(tags = "用户商户")
@LogModule(value = "用户商户管理")
public class RetailUserController extends BaseController {

    @Autowired
    private IRetailUserService iRetailUserService;

    @LogOperation("用户购物车列表")
    @ApiOperation(value = "用户购物车列表")
    @GetMapping("/list")
    public ResponseBean listByUserShoppingCart(
            @ApiParam(value = "名字") @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "用户类别") @RequestParam(name = "user_type", required = false) String userType,
            Page page){

        QueryWrapper<RetailUser> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(name)){
            queryWrapper.like("name",name);
        }
        if (StrUtil.isNotBlank(userType)){
            queryWrapper.like("user_type",userType);
        }
        Page pageVo = iRetailUserService.pageVo(page,queryWrapper);

        return ResponseBean.Success(pageVo);
    }

    @LogOperation("去编辑")
    @ApiOperation(value = "去编辑")
    @RequiresPermissions(value = { "003000350010" })
    @GetMapping("/toUpdate")
    public ResponseBean<RetailUser> toUpdate(@ApiParam(value = "id") @RequestParam(name = "id") String id) {
        RetailUser retailUser = iRetailUserService.getById(id);

        if (ObjectUtil.isNotNull(retailUser)) {
            return ResponseBean.Success(retailUser);
        } else {
            return ResponseBean.Fail();
        }
    }

    @LogOperation("去认证")
    @ApiOperation(value = "去认证")
    @RequiresPermissions(value = { "003000350015" })
    @GetMapping("/toVerify")
    public ResponseBean<RetailUserVo> toVerify(@ApiParam(value = "id") @RequestParam(name = "id") String id) {
        RetailUserVo verifyInfo = iRetailUserService.toVerifybyId(id);

        if (ObjectUtil.isNotNull(verifyInfo)) {
            return ResponseBean.Success(verifyInfo);
        } else {
            return ResponseBean.Fail("无认证信息");
        }
    }

    @LogOperation("编辑")
    @ApiOperation(value = "编辑")
    @RequiresPermissions(value = { "003000350010" })
    @PutMapping("/update")
    public ResponseBean update(@RequestBody RetailUser recode) {
        if (iRetailUserService.updateById(recode)) {
            return ResponseBean.Success();
        } else {
            return ResponseBean.Fail();
        }
    }


}
